<template>
  <div>
    <h1>Foo</h1>
    <ul>
      <li
        v-for="item in list"
        :key="item.id"
      >
        {{ item.text }}
      </li>
    </ul>
    <input
      type="text"
      v-model="text"
      @keyup.enter="addItem"
    >
    <h2>{{num}}</h2>
    <button @click="addNum">num++</button>
  </div>
</template>

<script>
// localStorage
// sessionStorage
// cookie
// ?num=100
// 数据持久化
import {mapState, mapActions} from 'vuex'
export default {
  name: "Foo",
  data() {
    return {
      text: '',
    }
  },
  computed: {
    ...mapState(['list', 'num'])
  },
  created() {
    // console.log(this.$store.state)
  },
  methods: {
    ...mapActions(['addNum']),
    addItem() {
      /*this.$store.commit('createItem', {
        text: this.text,
        id: Date.now()
      })*/
      this.$store.dispatch('createItemAction', {
        text: this.text,
        id: Date.now()
      })
      this.text = ''
    },
    /*addNum() {
      this.$store.dispatch('addNum')
    }*/
  }
}
</script>

<style scoped>

</style>